package Control;

import GameControl.GameControl;
import GameControl.GameState;
import Network.NetworkProtocol;
import java.io.Serializable;

/**
 * <code>InitReply</code> class instances represent initialization replies.
 * Incapsulates controller state and game state.
 * @author Dimon
 */
public class InitReply extends Command implements Serializable {

    /**
     * Incapsulated game state.
     */
    private GameState gameState;
    /**
     * Incapsulated swimline.
     */
    private SwimLines swimmingPool;

    /**
     * Constructs initialization command.
     */
    public InitReply() {
        gameState = GameControl.getState();
        swimmingPool = swim;
        Debug("created " + toString());
    }

    /**
     * Initializes controller with incapsulated data.<p>
     * <code>perform</code> should be executed each time it is recieved.
     */
    @Override
    public synchronized void perform() {
        Debug("initializing from " + toString());
        NetworkProtocol.StopInit();
        GameControl.setState(gameState);
        swim = swimmingPool;
        // Process NetworkProtocol initbuf:
        NetworkProtocol.ProcessInitBuf();
    }

    /**
     * Describes reply.
     * @return reply description
     */
    @Override
    public String toString() {
        return "initialization reply " + super.toString();
    }
}
